﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using HPortal.Lib;
using System.Collections;

namespace HPortal.Module.Menu
{
    public partial class Topmenu : System.Web.UI.UserControl
    {
        DataTable tbChannel = new DataTable();
        DataTable tbChannelID = new DataTable();
        String menu = "";
        public String GetChanne = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            //  String a1="";
            menu += "<ul id=\"navtabs\" class=\"navtabs floatcontainer\">";

            menu = GetChannel("");

            menu += "<li><a class=\"navtab\" href = \"/Backend\">Quản lý</a><ul></ul></li>";
            menu = menu.Replace("<ul></ul>", "");
            category.Text = menu;

            menu += "</ul>";
        }
        public String GetChannel(String PrentID)
        {

            String sql = "Select * from Channel where ParentID = '" + PrentID + "' and Locked='False' order by Priority ASC";
            DataTable tbChannel = DatabaseHelper.Select(sql);
            int i = 0;

            String idLi = "";
            String idUl = "";
            String idA = "";
            String classLi = "";
            String classUl = "";
            String classA = "";
            String styleUl = "";

            while (i < tbChannel.Rows.Count)
            {
                String linkhref = "/Default.aspx?ChannelID=" + tbChannel.Rows[i]["ChannelID"].ToString() + "";
                String nameLink = tbChannel.Rows[i]["Name"].ToString();
                String levelMenu = tbChannel.Rows[i]["LevelMenu"].ToString();
                String styleMenu = tbChannel.Rows[i]["StyleMenu"].ToString();

                if (int.Parse(levelMenu) == 1)
                {
                    idLi = "vbtab_forum";
                    classA = "navtab";
                    classUl = "floatcontainer";
                    styleUl = "display: none; left: 0px; top: 20px;";
                }
                if (int.Parse(levelMenu) == 2)
                {
                    if (int.Parse(styleMenu) == 1)
                    {
                        int j = 1;
                        idA = "yui-gen" + j;
                        classA = "popupctrl";
                        classUl = "popupbody";
                        idUl = "yui-gen" + j;
                        idLi = "vbmenu_community";
                        j++;
                        styleUl = "display: none; left: 0px; top: 20px;";
                    }
                    else
                    {
                        idUl = "vbflink_newposts";
                        classUl = "popupbody";
                        classUl = "yui-gen" + i;
                        idLi = "vbtab_forum";
                        styleUl = "display: none; left: 0px; top: 20px;";
                    }
                }
                if (int.Parse(levelMenu) == 3)
                {
                    idLi = "vbclink_members";
                }

                menu += "<li id=\"" + idLi + "\" class=\"" + classLi + "\"><a id=\"" + idA + "\" class=\"" + classA + "\"  href = \"" + linkhref + "\">" + nameLink + "</a>";
                if (int.Parse(styleMenu) == 1)
                {
                    menu += "<ul id=\"" + idUl + "\" class=\"" + classUl + "\" style=\"" + styleUl + "\">";
                }
                GetChannel(tbChannel.Rows[i]["ChannelID"].ToString());
                if (int.Parse(styleMenu) == 1)
                {
                    menu += "</ul></li>";
                }
                menu += "</li>";
                i++;
            }
            return menu;


            //String sql = "select * From Channel  order by Priority asc";
            //DataTable tbChannel = DatabaseHelper.Select(sql);
            //String sql1 = "select b.Name,b.ChannelID as ChannelID,b.ParentID,b.styleMenu  From (select * From Channel)a, (select * From Channel a ) b where a.ChannelID=b.ParentID and b.LevelMenu=2";

            //DataTable tbChannel1 = DatabaseHelper.Select(sql1);
            //String sql2 = "select b.Name,b.ChannelID,b.ParentID  From (select * From Channel)a, (select * From Channel a ) b where a.ChannelID=b.ParentID and b.LevelMenu=3";
            //DataTable tbChannel2 = DatabaseHelper.Select(sql2);

            //String sql3 = "select * From Channel";
            //DataTable tbChannel3 = DatabaseHelper.Select(sql3);

            //ArrayList arr = new ArrayList();

            //int i = 0;
            //int j = 0;
            //int n = 0;
            ////int k = 0;
            ////Int32 menu2 = 0;
            ////Int32 menu4 = 0;

            //for (i = 0; i < tbChannel.Rows.Count; i++)
            //{
            //    int levelMenu = int.Parse(tbChannel.Rows[i]["LevelMenu"].ToString());
            //    Int32 a = Convert.ToInt32(tbChannel.Rows[i]["ParentID"]);
            //    Int32 c = Convert.ToInt32(tbChannel.Rows[i]["LevelMenu"]);
            //    Int32 d = Convert.ToInt32(tbChannel.Rows[i]["styleMenu"]);
            //    menu += "<li id=\"vbtab_forum\">";
            //    if (a == 0)
            //    {
            //        menu += "<a class=\"navtab\" href = \"/Default.aspx?ChannelID=" + tbChannel.Rows[i]["ChannelID"].ToString() + "\">" + tbChannel.Rows[i]["Name"] + "</a>";
            //        if (d != 1)
            //        {
            //            menu += "<ul class=\"floatcontainer\">";
            //            for (j = 0; j < tbChannel1.Rows.Count; j++)
            //            {
            //                menu += "<li id=\"vbflink_faq\"><a class=\"\" href = \"/Default.aspx?ChannelID=" + tbChannel1.Rows[j]["ChannelID"].ToString() + "\">" + tbChannel1.Rows[j]["Name"] + "</a>";
            //                Int32 e = Convert.ToInt32(tbChannel1.Rows[j]["styleMenu"]);
            //                if (e == 3)
            //                {
            //                    menu += "<ul id=\"yui-gen0\" class=\"popupbody\" style=\"display: block; left: 0px; top: 20px;\">";
            //                    for (n = 0; n < tbChannel2.Rows.Count; n++)
            //                    {
            //                        menu += "<li id=\"vbclink_members\"><a class=\"\" href = \"/Default.aspx?ChannelID=" + tbChannel2.Rows[n]["ChannelID"].ToString() + "\">" + tbChannel2.Rows[n]["Name"] + "</a></li>";
            //                    }
            //                    menu += "</ul>";
            //                }
            //            }
            //            menu += "</li></ul>";
            //        }
            //    }
            //    menu += "</li>";

            //}

            //return menu;

        }
    }
}